package com.lagou.search.manager.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lagou.search.entity.Order;
import com.lagou.search.entity.es.EsOrder;
import com.lagou.search.manager.IEsOrderManager;
import com.lagou.search.manager.IOrderManager;
import com.lagou.search.mapper.OrderMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单通用服务接口
 * @author yzh
 * @since 2021/12/2
 **/
@Service
public class OrderManagerImpl extends ServiceImpl<OrderMapper, Order> implements IOrderManager {

    @Autowired
    private IEsOrderManager esOrderManager;

    @Override
    public void saveWithEs(Order order) {
        this.save(order);
        EsOrder esOrder = new EsOrder();
        BeanUtils.copyProperties(order, esOrder);
        esOrderManager.save(esOrder);
    }

    @Override
    public void removeWithEs(Long id) {
        this.removeById(id);
        esOrderManager.remove(id);
    }

}